package com.crs.mapper;

import com.crs.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserMapper {
    /**
     * 根据用户名查找用户
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User findByUsername(String username);

    /**
     * 插入用户信息
     * @param user1
     */
    void insert(User user1);

    /**
     * 判断手机号是否被注册过
     * @param phone
     * @return
     */
    @Select("select * from user where phone = #{phone}")
    Boolean existsByPhone(String phone);

    /**
     * 判断邮箱是否被注册过
     * @param email
     * @return
     */
    @Select("select count(*) from user where email = #{email}")
    int existsByEmail(String email);

    /**
     * 封禁用户账号
     * @param userId
     */
    @Update("update user set status = 0 where id = #{userId}")
    void update(Long userId);

    /**
     * 通过id查找用户
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User findById(Long userId);

    /**
     * 修改用户状态为封禁或解除状态
     * @param status
     * @param userId
     */
    @Update("update user set status = #{status} where id = #{userId}")
    void updateStatus(Integer status, Long userId);

    /**
     *
     * @param userId
     * @param changeValue
     */
    @Update("update user set credit_score = credit_score+#{changeValue} where id = #{userId}")
    void updateCreditScore(Long userId, BigDecimal changeValue);

    /**
     * 更新用户的已经评论的状态
     * @param currentId
     */
    @Update("update user set has_commented_today = 1 where id = #{currentId}")
    void updateHasCommentedToday(Long currentId);
}
